package com.aliatry.dateTimeApi;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;

/**
 * @author Simon
 */
public class LocalDateTimeMain {

    public static void test() {
        LocalDate today = LocalDate.now();
        LocalTime nowTime = LocalTime.now();
        LocalDateTime dateTime = LocalDateTime.now();

        System.out.println("today: " + today);

        System.out.println("getYear: " + today.getYear());

        System.out.println("getMonth: " + today.getMonth());

        System.out.println("getMonthValue: " + today.getMonthValue());

        System.out.println("getDayOfMonth: " + today.getDayOfMonth());

        System.out.println("getDayOfWeek: " + today.getDayOfWeek());

        // 日期加减
        System.out.println("LocalDate.plusYears(1L): " + today.plusYears(1L));
        System.out.println("LocalDate.plusYears(-1L): " + today.plusYears(-1L));
        System.out.println("LocalTime.plusHours(1L): " + nowTime.plusHours(1L));
        System.out.println("LocalDateTime.plusYears(1L).plusHours(-1L): " + dateTime.plusYears(1L).plusHours(-1L));

        // 日期比较
        LocalDate localDate = LocalDate.of(1997, 11, 11);
        LocalDateTime localDateTime = LocalDateTime.of(1997, 11, 11, 12, 30, 59);
        System.out.println("'1997-11-11'.isBefore(today): " + localDate.isBefore(today));
        System.out.println("'1997-11-11 12:30:59'.isAfter(dateTime): " + localDateTime.isAfter(dateTime));

    }
}
